﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyClassLibrary;
using MyDB;

namespace MyProgram
{
    public partial class FrmDrugFreqAdd : FrmBaseModify
    {
        public FrmDrugFreqAdd()
        {
            InitializeComponent();
        }

        internal string drugFreq;
        internal int drugDay;

        MedicareDataClassesDataContext db = new MedicareDataClassesDataContext();

        private void button1_Click(object sender, EventArgs e)
        {

            MyDB.DrugFrequency div = new MyDB.DrugFrequency { 用藥頻率 = this.textBox1.Text, 轉換天數 = int.Parse(this.textBox2.Text) };

            if (this.label3.Text == "")
            {
                db.DrugFrequencies.InsertOnSubmit(div);
            }
            else
            {
                var q = (from f in db.DrugFrequencies
                         where f.用藥頻率 == this.label3.Text
                         select f).First();

                q.用藥頻率 = this.textBox1.Text;
                q.轉換天數 = int.Parse(this.textBox2.Text);
            }

            db.SubmitChanges();

            this.Close();
        }

        private void FrmDrugFreqAdd_Load(object sender, EventArgs e)
        {
            this.label3.Text = drugFreq;
            this.label8.Text =drugDay.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
